package cn.com.jslh.boarpro.util.template;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/11/17.
 */

public class TemplateFactory {
    public static ArrayList<Class<? extends AddTempBaseItem>> classArrayList;

    static {
        classArrayList = new ArrayList<>();
        classArrayList.add(ReMarkTempalte.class);
        classArrayList.add(DateTempalte.class);
        classArrayList.add(RadioTempalte.class);
        classArrayList.add(SelectSearchTempalte.class);
        classArrayList.add(TxtScanTempalte.class);
        classArrayList.add(TxtTempalte.class);
        classArrayList.add(SelectTempalte.class);
    }

    public static AddTempBaseItem createTempItem(String name) {
        // 获取要解析的类
        AddTempBaseItem item = null;
        Class cls = TemplateFactory.class;
        // 拿到所有Field
        if (classArrayList == null || classArrayList.size() == 0)
            return null;
        for (Class clss : classArrayList) {
            try {
                AdapterInterface adapterInterface = (AdapterInterface) clss.newInstance();
                if (adapterInterface.getFlag().equals(name)) {
                    item = (AddTempBaseItem)adapterInterface;
                    break;
                }
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }

        }
        return item;
    }
}
